import { consola } from 'consola'
import fg from 'fast-glob'
import { remove } from 'fs-extra'

export const commandList = ['clean'] as const

export function run(command: (typeof commandList)[number]) {
  switch (command) {
    case 'clean':
      clean()
      break
    default:
      consola.error(`Command ${command} not found`)
      break
  }
}
async function clean() {
  consola.start('Cleaning...')
  await remove('pnpm-lock.yaml')
  const nodeModulesPaths = await fg('**/node_modules', { onlyDirectories: true })
  await Promise.all(nodeModulesPaths.map(path => remove(path)))
}
